#!/bin/bash

awk -F ':' 'BEGIN {
    #定义列标题
    username_header = "UserName"
    groupname_header = "GroupName"
    shell_header = "Shell Path"
    
    #打印标题，并确保字段名与内容按列对齐
    printf "%-20s %-20s %-s\n", username_header, groupname_header, shell_header
    #打印分隔线
    print "----------------------------------------"
}

{
    #使用printf格式化输出每行的用户名、组名和默认shell路径
    printf "%-20s %-20s %-s\n", $1, $4, $7
    #统计每种shell路径出现的次数
    shells[$7]++
}

END {
    #打印结束的分隔线
    print "----------------------------------------"
    #打印每种shell路径的出现次数
    for (shell in shells) 
    {
        printf "Shell %s is used %d times\n", shell, shells[shell]
    }
}' /etc/passwd > awk1.out

#打印输出文件完成的信息
echo "Output written to awk1.out"
